<?php
namespace app\admin\logic;
use app\common\model\ConsultBanner;
use app\common\logic\BaseLogic;
Class AbannerLogic extends BaseLogic{
    public function listing($page_size = 10)
    {
        $where['state'] = 1;
        $r = ConsultBanner::where($where)->paginate($page_size)->toArray();
        return $r;
    }

    public function create($data)
    {
        $data['state'] = 1;
        $data['sort'] = 1;
        (new ConsultBanner())->save($data);
        return true;
    }

    public function update($data, $methods = 'post')
    {
        if ($methods === 'get') {
            $r = ConsultBanner::get($data);
        } else {
            if (empty($data['img']))
                unset($data['img']);
            $r = ConsultBanner::update($data);
        }
        return $r;
    }

    public function delete($ids)
    {
        $str = trim($ids,',');
        $_arr = explode(',',$str);
        $where[] = ['id','in',$_arr];
        $r = ConsultBanner::where($where)->delete();
        return $r;
    }
}